package com.jr.controller;

import com.jr.entry.User;
import com.jr.service.UserService;
import com.jr.service.impl.UserServiceImpl;
import com.jr.util.ResultObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController /*替换@RestController=@Controller + @ResponseBody*/
@RequestMapping("/Us/")
public class UserController {
    @Autowired
    private UserServiceImpl userMapperService;
    @Autowired
    private ResultObject result;

    @RequestMapping("add")
    public ResultObject add(User user){
        int register = userMapperService.register(user);
        result.setStatus(register);
        result.setResult("成功");
        return result;
    }

    @RequestMapping("login")
    public ResultObject login(User user){
        User register = userMapperService.login(user);

        if (register!=null){
            result.setStatus(1);
            result.setResult("成功");
        }else {
            result.setStatus(-1);
            result.setResult("失败");
        }

        return result;
    }
}
